<template>
	<view class="">
		<view class="form-body">
			<u-form labelPosition="left" :model="formData" :rules="rules" ref="form" labelWidth="auto"
				errorType="toast">
				
				<u-form-item label="选择联创" prop="staffName" borderBottom  @click="showStaff">
					<u-input v-model="formData.staffName" border="none" placeholder="请选择联创" inputAlign="right"
						:readonly="true">
					</u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				
				<u-form-item label="入股金额" borderBottom>
					<view class="flex align-center">
						<u-input v-model="formData.amount" border="none" inputAlign="right" type="number"></u-input>
						<text class="ml-10">元</text>
					</view>
				</u-form-item>
				<u-form-item label="入股份额" borderBottom>
					<view class="flex align-center">
						<u-input v-model="formData.stock" border="none" inputAlign="right" type="number"></u-input>
						<text class="ml-10">份</text>
					</view>
				</u-form-item>

				<u-form-item label="股本可消费" borderBottom>
					<view class="flex justify-end">
						<view class="">
							<u-radio-group v-model="formData.rechargeBalance" placement="row">
								<u-radio activeColor="#fa436a" :name="-1" label="否"></u-radio>
								<u-radio activeColor="#fa436a" :name="1" label="是"></u-radio>
							</u-radio-group>
						</view>
					</view>
				</u-form-item>
				<u-form-item label="股本可退出" borderBottom>
					<view class="flex justify-end">
						<view class="">
							<u-radio-group v-model="formData.refundable" placement="row">
								<u-radio activeColor="#fa436a" :name="-1" label="否"></u-radio>
								<u-radio activeColor="#fa436a" :name="1" label="是"></u-radio>
							</u-radio-group>
						</view>
					</view>
				</u-form-item>
				<u-form-item label="备注" prop="remark">
					<u--textarea v-model="formData.remark" border="none" placeholder="建议输入50字以内" inputAlign="right">
					</u--textarea>
				</u-form-item>
				<!-- <u-form-item label="详细说明" prop="contentBody" labelPosition="top">
					<view class="mt-20">
						<u-textarea v-model="formData.contentBody" placeholder="请输入该步骤说明( 换行用 / 间隔 )"></u-textarea>
					</view>
				</u-form-item> -->
			</u-form>
		</view>
		<u-gap height="20"></u-gap>
		<view class="">
			<u-button type="primary" color="#fa436a" text="保存" @click="onSubmit"></u-button>
		</view>
		<u-picker :show="staff.show" :columns="staff.columns" keyName="nickName" @cancel="staff.show=false"
			title="选择联创" @confirm="staffConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isEdit: false,
				fileList: [],
				formData: {
					staffId:0,
					staffName:'',
					amount:0,
					stock:0,
					rechargeBalance:1,
					refundable:1,
					remark:''
				},
				newFormData: {
					staffId:0,
					channel:'uniapp',
					typeCode:'normal',
					startTime:'',
					endTime:'2099/12/31',
					amount:0,
					stock:0,
					rechargeBalance:1,
					refundable:1,
					remark:''
				},
				staff: {
					show: false,
					columns: []
				},
				rules: {
					amount: [
						{
							required: true,
							message: '请输入股本',
							trigger: ['change', 'blur']
						}
					],
					stock: [
						{
							required: true,
							message: '请输入份额',
							trigger: ['change', 'blur']
						}
					],
				}
			}
		},
		onLoad(option) {
			let that = this
			that.getStaff();
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			showStaff(){
				let that = this
				console.log("that.staff.columns",that.staff.columns);
				that.staff.show = true
			},
			getStaff() {
				let that = this
				that.$reqPost('GetStaffPageList',{ page:1, limit:100 }).then(res=>{
					that.staff.columns  = [res.data]
					console.log("that.staff.columns",that.staff.columns);
				})
			},
			staffConfirm(arr){
				this.formData.staffId = arr.value[0].id
				this.formData.staffName = arr.value[0].nickName
				this.staff.show = false
				console.log("this.formData.staffName",this.formData.staffName);
			},
			onSubmit() {
				console.log("click");
				let that = this;
				that.$refs.form.validate().then(res => {
					const currentDate = new Date();
					
					that.newFormData.staffId=that.formData.staffId
					that.newFormData.startTime=currentDate.getFullYear() + "/" + (currentDate.getMonth() + 1) + "/" + currentDate.getDate();
					that.newFormData.amount=that.formData.amount
					that.newFormData.stock=that.formData.stock
					that.newFormData.rechargeBalance=that.formData.rechargeBalance===1?true:false;
					that.newFormData.refundable=that.formData.refundable===1?true:false;
					that.newFormData.remark=that.formData.remark
					
					console.log("that.newFormData",that.newFormData);
					
					that.$reqJsonPost('StoreStaffStockDoCreate',
						that.newFormData
					).then(res => {
						uni.redirectTo({
							url:'/pages/app/index'
						})
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.form-body {
		padding: 20rpx 20rpx 0 20rpx;
		background-color: #fff;
	}

	.pro-box {
		.seims {
			font-size: 28rpx;
			padding: 20rpx;
			color: #999;
		}

		.pro-list {
			padding: 0 20rpx;
			margin-bottom: 8rpx;
			background-color: #fff;
			.delBtn {
				border: 1px #fa436a solid;
				color: #fa436a;
				font-size: 22rpx;
				padding: 0 20rpx;
				border-radius: 6rpx;
			}
		}
	}
	.addBtn {
		background-color: #fff;
		padding:0 20rpx 20rpx 20rpx;
		text-align: center;
		color: #fa436a;
		font-size: 28rpx;
		font-weight: 600;
	}
</style>
